home *** CD-ROM | disk | FTP | other *** search
- Path: cs.vu.nl!sun4nl!xs4all!marketgraph!rvg
- From: rvg@marketgraph.xs4all.nl (Ruud van Gaal)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: C compiler problem
- Message-ID: <3005pbd60.alamito@marketgraph.xs4all.nl>
- Date: Tue, 30 Jan 96 15:05:48 CET
- References: <4ek3b2$a5k@nntp.novia.net>
- Reply-To: rvg@marketgraph.xs4all.nl
- X-Newsreader: Alamito Mail and News Manager (V2.0.4 for Waffle) registered to MARKETGRAPH VISUAL AUTOMATION
-
- In <4ek3b2$a5k@nntp.novia.net> tsyslo@oasis.novia.net (Tony Syslo) wrote:
-
- >I have a friend who is converting a CNET BBS game from ARREX to C.
- >Here is his request:
- >
- >Can anyone tell me why this program is not compiling?
- >I am using SAS/C 6.50, and am getting a BPTR error on line 35 with the
- >"struct FileHandle *".
-
- OK, seeing that you use AREXX more than C, here are the complete docs:
-
- >/* File Open */
- >
- >#include <clib/dos_protos.h>
- >#include <dos/dos.h>
- >#include <stdio.h>
- >#include <exec/types.h>
- >
- >int main();
-
- Can be left out.
-
- >
- > char name[80];
- > int age;
- >
- >int main()
-
- void main(void) is better prototyped in C. C++ might use void main()
-
- >{
- > struct FileHandle *file_handle;
-
- BPTR file_handle;
-
- > long bytes_written;
- > long bytes_read;
- >
- > printf("Enter your name: ");
- > scanf("%s",name);
- > printf("\nEnter your age: ");
- > scanf("%d",&age);
- >
- >
- > file_handle=(struct FileHandle *)
- > Open("RAM:You.dat",MODE_NEWFILE);
-
- file_handle=Open("RAM:You.dat",MODE_NEWFILE); // Open returns a
- BPTR
-
- > /* Have we opened the file successfully? */
- > if(file_handle==NULL)
- > {
- > printf("Could not open the file!\n");
- > Exit(0);
- > }
- > /* We have now opened a file, and are ready to start writing: */
- > bytes_written=Write(file_handle,name,sizeof(name));
- > bytes_written=bytes_written+Write(file_handle,age,sizeof(age));
-
- bytes_written=bytes_written+Write(file_handle,&age,sizeof(age)); //
- Address
-
- > if(bytes_written!=sizeof(name)+sizeof(age))
- > {
- > printf("Could not save the list!\n");
- > Close(file_handle);
- > Exit(0);
- > }
- > else
- > printf("Saved successfully!\n");
- > printf("Memory cleared!\n");
-
- Memory is not cleared at this point. Besides, name[1]-name[79] will still
- contain the name pieces after the following:
-
- > name="";
-
- You cannot assign to strings like this in C. In C, 'name' is a pointer to the
- char array as defined before main(). You must do 'strcpy(name,"")' or
- name[0]=0.
-
- > age=0;
- > printf("Loading!\n");
- > Seek(file_handle,0,OFFSET_BEGINNING);
- > bytes_read=Read(file_handle,name,sizeof(name));
- > bytes_read=bytes_read+Read(file_handle,age,sizeof(age));
-
- bytes_read=bytes_read+Read(file_handle,&age,sizeof(age)); // &
-
- > if(bytes_read!=sizeof(name)+sizeof(age))
- > {
- > printf("Could not read the list!\n");
- > Close(file_handle);
- > Exit(0);
- > }
- > /* Print out the data: */
- > printf("Hello, %s!\",name);
-
- printf("Hello, %s!\n",name); // Typo assumed; \" is chr(34);
- string not ended
-
- > printf("You are %d years old!\n",age);
- > /* Close the file: */
- > Close(file_handle);
- >}
- >
- >Also, are there any good random number generators I could use? I am in need
- >of a script, or something, that is fast, for a game I am writing, or
- >converting, rather... Anything will work, even if it is a psuedo-random
- >generator.
-
- Try srand(<n>) to set rand seek (for pseudo random streams), use
- n=rand()%<mymax> to get random numbers. #include <stdlib.h>
-
- >Thanx for any and all help!
- >
-
- There you go. It compiled &ran on my machine (SAS v6.51).
-
- --
- Ruud van Gaal
- MarketGraph Visual Automation
- E-Mail : rvg@marketgraph.xs4all.nl
- DoomShell 4.5 homepage: http://www.xs4all.nl/~jwkorver
- "...Works fascinates me. I could sit and watch it for hours..."
-
-